﻿﻿// Houssem Dellai  
// houssem.dellai@ieee.org  
// +216 95 325 964  
// Studying Software Engineering  
// in the National Engineering School of Sfax (ENIS)  

using System;
using System.Windows.Media;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Controls.Maps;
using System.Device.Location;
using System.Xml;
using System.IO;
using System.Text;

namespace MonitoringFloty_WindowsPhoneClient
{

    
    public partial class MainPage : PhoneApplicationPage
    {
        public Pushpin SelectedPosition;

        // Constructor
        public MainPage()
        {
            InitializeComponent();

            map1.CredentialsProvider = new ApplicationIdCredentialsProvider("AkkhMdTgAg5f6tH6uollZ4Vh1dU0-CmXB_8CnhLTHdJzMIty9hyN5jNhciJuthZW");
            map1.Hold += new EventHandler<System.Windows.Input.GestureEventArgs>(map1_Hold);
            SelectedPosition = new Pushpin();
            SelectedPosition.Background = new SolidColorBrush(Colors.Yellow);
            SelectedPosition.Foreground = new SolidColorBrush(Colors.Blue);
        }

        void map1_Hold(object sender, System.Windows.Input.GestureEventArgs e)
        {
            if (!map1.Children.Contains(SelectedPosition))
                map1.Children.Add(SelectedPosition);
            GeoCoordinate coords  = map1.ViewportPointToLocation(e.GetPosition(this.map1));
            SelectedPosition.Location = coords;
            positionUpdater posUpdater = positionUpdater.Instance;
            posUpdater.updatePosition(coords);
            //System.Diagnostics.Debug.WriteLine("TEST {0},{1}",coord.Latitude,coord.Longitude);
            

        }

        private void zoomIn_click(object sender, EventArgs e)
        {
            map1.ZoomLevel++;
        }

        private void zoomOut_click(object sender, EventArgs e)
        {
            map1.ZoomLevel--;
        }

        private void Aerial_click(object sender, EventArgs e)
        {
            map1.Mode = new AerialMode(true);
        }

        private void Road_click(object sender, EventArgs e)
        {
            map1.Mode = new RoadMode();
        }

        private void SwitchToGPS_click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/GpsPage.xaml", UriKind.Relative));
        }

        private void SetDeviceID_click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/DeviceIdSetup.xaml", UriKind.Relative));
        }

        private void ApplicationBarMenuItem_Click(object sender, EventArgs e)
        {
            NavigationService.GoBack();
        }

    }
}